package com.xxl.mq.sample.springboot.mqcomsumer;

import com.xxl.mq.client.consumer.IMqConsumer;
import com.xxl.mq.client.consumer.MqResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * Created by xuxueli on 16/8/28.
 */
@Service
public class DemoCMqComsumer implements IMqConsumer {
    private Logger logger = LoggerFactory.getLogger(DemoCMqComsumer.class);

    private static final String randomGroup = UUID.randomUUID().toString().replaceAll("-", "");

    @Override
    public MqResult consume(String data) throws Exception {
        logger.info("[DemoCMqComsumer] 消费一条消息:{}", data);
        return MqResult.SUCCESS;
    }

    @Override
    public String topic() {
        return "topic_1";
    }

    @Override
    public String group() {
        // randomGroup必须是固定值，不能是调用group()方法时动态生成的！！
        return randomGroup;
    }
}
